//
//  BaseViewController.m
//

#import <QuartzCore/QuartzCore.h>
#import "BaseViewController.h"
#import "UIBarButtonItem+ClearBackground.h"

#define kViewControllerBgColor [UIColor whiteColor]


@interface BaseViewController ()


@end

@implementation BaseViewController

- (void)dealloc{
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.startTimeStr = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
}

- (id)init{
    self = [super init];
    if (self) {
       
    }
    return self;
}



- (void)viewDidLoad{
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    [self.navigationController.navigationBar setTranslucent:NO];

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(kScreenWidth, 0.5)] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    
    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(kScreenWidth, 0.5)]];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#191919"], NSFontAttributeName : [UIFont systemFontOfSize:16]}];
    
    
    
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *barApp = [[UINavigationBarAppearance alloc]init];
        
        UIView *barBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, kNavigationBarHeight)];
        
        barBackgroundView.backgroundColor = [UIColor whiteColor];
        
        UIImage *backImage = [UIImage imageFromView:barBackgroundView];
        
        [barApp setBackgroundImage:backImage];
        
        barApp.shadowColor = UIColor.clearColor;

        barApp.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"#022D06"], NSFontAttributeName : [UIFont fontWithName:kFuturaMedium size:16]};
                
        
        barApp.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        self.navigationController.navigationBar.scrollEdgeAppearance = barApp;
        self.navigationController.navigationBar.standardAppearance = barApp;
        
        [UITableView appearance].sectionHeaderTopPadding = 0;
        
    }
    
    if (self.navigationController != nil && self.navigationController.childViewControllers.count > 1) {
        UIBarButtonItem *backButton = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"icon_return"] highlightImage:nil target:self action:@selector(back)];
        self.navigationItem.leftBarButtonItem = backButton;
    }
    
    self.view.backgroundColor =  [UIColor colorWithHexString:@"#F1F3F2"];
    
}

- (void)back{
    [self.view endEditing:YES];
    if (self.navigationController.visibleViewController == self) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
